package io.github.eric.urpc.server;

import io.github.eric.urpc.core.config.AbstractConfig;
import io.github.eric.urpc.core.config.AbstractContext;
import io.github.eric.urpc.core.config.EventExecutorState;

import java.util.Collections;
import java.util.concurrent.ExecutorService;

public class ServerContext extends AbstractContext implements ServerConfig, EventExecutorState {
    private int listenPort;
    private int heartBeatTimeout;

    ServerContext(ExecutorService rpcExecutor) {
        super(AbstractConfig.SERVER, rpcExecutor);
        addRpcControllers(Collections.singletonList(new ServerCoreRpcController(this)));
    }

    @Override
    public int getListenPort() {
        return listenPort;
    }

    public void setListenPort(int listenPort) {
        this.listenPort = listenPort;
    }

    @Override
    public int getHeartBeatTimeout() {
        return heartBeatTimeout;
    }

    public void setHeartBeatTimeout(int heartBeatTimeout) {
        this.heartBeatTimeout = heartBeatTimeout;
    }

    @Override
    public ServerConnectionManager getConnectionManager() {
        return (ServerConnectionManager) super.getConnectionManager();
    }
}
